package com.yonyou.pmclouds.workquality.mapper;

import com.yonyou.pmclouds.basecom.dao.BaseMapper;
import com.yonyou.pmclouds.workquality.entity.WorkqualityVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface WorkqualityMapper extends BaseMapper<WorkqualityVO> {

    List<WorkqualityVO> queryByPage(@Param("condition") String condition[], @Param("pkTenant") String pkTenant, @Param("start") Integer start, @Param("limit") Integer limit, @Param("enableStatus") byte enableStatus);

    int countPage(@Param("condition") String[] condition, @Param("pkTenant") String pkTenant, @Param("enableStatus") byte enableStatus);

    @Select("select count(*) from pmbd_workquality where checkname = #{checkname} and pk_workquality != #{pkWorkquality} and pk_tenant = #{pkTenant} and dr=0 ")
    int checkUpdateRepeat(WorkqualityVO vo);

    @Select("select count(*) from (select pk_inspectstandard from pm_siteinspection where pk_inspectstandard = #{pkWorkquality} and dr=0 union select pk_inspectstandard from pm_constructionlog where pk_inspectstandard = #{pkWorkquality} and dr=0) as ta ")
    int checkUpdateUsed(WorkqualityVO vo);


    @Select("select count(*) from pmbd_workquality where checkname = #{checkname} and pk_tenant = #{pkTenant} and dr = 0 ")
    int countSameWorkquality(@Param("checkname") String checkname, @Param("pkTenant") String pkTenant);

    List<WorkqualityVO> queryByIds(@Param("pks") String pks);

    WorkqualityVO queryByProcedure(String procedure);


    @Select("select checkname from pmbd_workquality where pk_tenant = #{pkTenant, javaType=string} and dr = 0 "
            + "  and checkname in  (${checkNames})")
    String[] checkNames(@Param("pkTenant") String pkTenant, @Param("checkNames") String checkNames);

    List<WorkqualityVO> queryByChecktypes(@Param("pkTenant") String pkTenant, @Param("checktypes") int... checktypes);

    WorkqualityVO queryOneByProcedureAndType(@Param("procedure") String procedure, @Param("checkType") int checkType);

    /**
     * 查询工序关联检查标准
     *
     * @param procedure
     * @param checkType
     * @return
     */
    List<WorkqualityVO> queryByProcedureAndType(@Param("procedure") String procedure, @Param("checkType") int checkType, @Param("pkTenant") String pkTenant);

    /**
     * 查询出所有未关联工序的检查标准
     *
     * @param tenantId
     * @return
     */
    List<WorkqualityVO> queryAllNotAssociatedChecks(@Param("pkTenant") String tenantId, @Param("checkType") int checkType);

    List<WorkqualityVO> queryByPkProcedures(@Param("set") Set<Set<String>> pkProcedures);
}
